/*
 * @lc app=leetcode.cn id=876 lang=javascript
 *
 * [876] 链表的中间结点
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var middleNode = function(head) {
  let ret = new ListNode(null, head);
  let fast = ret, slow = ret;
  while(fast.next && fast.next.next) {
    slow = slow.next;
    fast = fast.next.next;
  }
  slow = slow.next;

  return slow;
};

var middleNode = function(head) {
  let ret = new ListNode(null, head);
  let fast = ret, slow = ret;
  while(fast && fast.next) {
    slow = slow.next;
    fast = fast.next.next;
  }
  if(fast) {
    slow = slow.next;
  }
  return slow;
};


// @lc code=end

